package com.kevin.controller.controller;

import com.alibaba.fastjson.JSON;
import com.kevin.controller.config.websocket.MyWebSocketHandler;
import com.kevin.service.dto.WsMsgDTO;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * 员工控制器
 *
 * @author wh
 * @date 2023/03/27
 */
@RestController
@RequestMapping("wsm")
@AllArgsConstructor
@Api(tags = "wsm管理")
public class WsController {

    @GetMapping(value = "/msg/new")
    public void sendNewMsg(String message, String to) {
        WsMsgDTO dto = new WsMsgDTO();
        dto.setFrom(1L);
        dto.setFromNickName("wh");
        dto.setTime(LocalDateTime.now());
        dto.setContent(message);
        dto.setTo(to);
        MyWebSocketHandler.sendMessage(to, JSON.toJSONString(dto));
    }

}
